import random

from constant import SCREEN_X, SCREEN_Y, BOARD_SIZE, INIT_OFFSET


class Food:
    def __init__(self, pygame):
        self.rect = pygame.Rect(-BOARD_SIZE * INIT_OFFSET, 0, BOARD_SIZE, BOARD_SIZE)

    def remove(self):
        self.rect.x = -BOARD_SIZE * INIT_OFFSET

    def set(self):
        if self.rect.x == -BOARD_SIZE * INIT_OFFSET:
            all_pos_left = []
            all_pos_top = []
            # 不靠墙太近 25 ~ SCREEN_X-25 之间
            for pos in range(BOARD_SIZE, SCREEN_X - BOARD_SIZE, BOARD_SIZE):
                all_pos_left.append(pos)


            for pos in range(BOARD_SIZE, SCREEN_Y - BOARD_SIZE, BOARD_SIZE):
                all_pos_top.append(pos)
            self.rect.left = random.choice(all_pos_left)
            self.rect.top = random.choice(all_pos_top)
            print(self.rect)
